<template>
  <div class="about">
    <nav>
      <router-link to="/">Home</router-link> |
      <router-link to="/about">About</router-link> |
      <router-link to="/index">index</router-link>
    </nav>
    <h1>index</h1>
    <el-button @click="button('1')">按钮1</el-button>
    <el-button @click="button('2')">按钮2</el-button>
    <el-button @click="logOut()">退出</el-button>
    <p>{{value}}</p>
    <w-button @click="handleBtnClick()"></w-button>
  </div>
</template>
<script>
export default {
  data() {
    return {
      value: "",
    };
  },
  methods: {
    handleBtnClick() {
      console.log('111111')
    },
    logOut() {
      this.$store.state.info.info = {};
      localStorage.removeItem('userInfo');
      this.$router.push({
        path: '/login',
        replace: true,
      })
    },
    button(type) {
      // this.handel(type).then((res)=>{
      //   console.log(res)
      //   this.value = res;
      // }).catch((rej)=>{
      //   console.log(rej)
      //   this.value = rej;
      // })
      this.handel2(type);
    },
    handel1(val) {
      console.log(val)
      return new Promise((resolve, reject) => {
        setTimeout(()=>{
          if(val === '1') {
            resolve('111')
          }else{
            reject('222')
          }
        },1000)
      })
    },
    handel2(val) {
      let val1 = new Promise((resolve, reject) => {
        setTimeout(()=>{
          if(val === '2') {
            resolve('111')
          }else{
            reject('222')
          }
        },1000)
      })
      let val2 = new Promise((resolve, reject) => {
        setTimeout(()=>{
          if(val === '2') {
            resolve('111')
          }else{
            reject('222')
          }
        },2000)
      })
      let val3 = new Promise((resolve, reject) => {
        setTimeout(()=>{
          if(val === '2') {
            resolve('111')
          }else{
            reject('222')
          }
        },3000)
      })
      Promise.allSettled([val1,val2,val3]).then(res=>{
        console.log(res)
      }).catch(rej=>{
        console.log(rej)
      })
    },
  },
};
</script>
